// UVa12657 Boxes in a Line
// 刘汝佳
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int NN = 1e5 + 4;
int Left[NN], Right[NN];
inline void link(int L, int R) { Right[L] = R; Left[R] = L;}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  for (int n, m, kase = 1; cin >> n >> m; kase++) {
    for (int i = 1; i <= n; i++) Left[i] = i - 1, Right[i] = (i + 1) % (n + 1);
    Right[0] = 1, Left[0] = n;
    bool inv = false;
    for (int i = 0, op, X, Y; i < m; i++) {
      cin >> op;
      if (op == 4) { inv = !inv; continue; }
      cin >> X >> Y;
      if (op == 3 && Right[Y] == X) swap(X, Y);
      if (op != 3 && inv) op = 3 - op;
      if (op == 1 && X == Left[Y]) continue;
      if (op == 2 && X == Right[Y]) continue;
      int LX = Left[X], RX = Right[X], LY = Left[Y], RY = Right[Y];
      if (op == 1) link(LX, RX), link(LY, X), link(X, Y);
      else if (op == 2) link(LX, RX), link(Y, X), link(X, RY);
      else if (op == 3) {
        if (Right[X] == Y) link(LX, Y), link(Y, X), link(X, RY);
        else link(LX, Y), link(Y, RX), link(LY, X), link(X, RY);
      }
    }
    LL ans = 0;
    for (int i = 1, b = 0; i <= n; i++) {
      b = Right[b];
      if (i % 2 == 1) ans += b;
    }
    if (inv && n % 2 == 0) ans = (LL)n * (n + 1) / 2 - ans;
    printf("Case %d: %lld\n", kase, ans);
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》例题6-5
注意Link函数是如何简化链表的各种操作，同时注意翻转标志的使用
*/
// 26594668 12657 Boxes in a Line Accepted  C++ 0.060 2021-07-21 02:26:05